<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>用户登录</title>
    <style>
        legend{
            color: black;
            text-align: center;
        }
        body {
            font-family: Arial, sans-serif;
            color: white;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }
        .login-container {
            background-color: white;
            padding: 20px;
            border-radius: 5px;
        }
        .login-container h2 {
            margin-bottom: 20px;
            color: #663399;
        }
        .login-container input[type="text"],
        .login-container input[type="password"] {
            width: calc(100% - 22px);
            padding: 10px;
            margin-bottom: 10px;
            border: 1px solid #ccc;
            border-radius: 3px;
        }
        .login-container button {
            width: 100%;
            padding: 10px;
            background-color: #663399;
            color: white;
            border: none;
            border-radius: 3px;
            cursor: pointer;
        }
        .login-container button:hover {
            background-color: #5a3f8a;
        }
        .error {
            color: red;
            font-size: 0.9em;
        }
    </style>
</head>
<body>
    <fieldset>
      <legend>用户登录</legend>
    <div class="login-container">
        <form id="loginForm">
            <input type="text" id="username" placeholder="用户名" required>
            <input type="password" id="password" placeholder="密码" required>
            <button type="button" onclick="validateForm()">登录</button>
            <div id="error-message" class="error"></div>
        </form>
    </div>
    </fieldset>
    <script>
        function validateForm() {
            var username = document.getElementById('username').value;
            var password = document.getElementById('password').value;
            var errorMessage = document.getElementById('error-message');

            errorMessage.textContent = ''; // 清空之前的错误信息

            if (username.length < 8 || username.length > 20) {
                errorMessage.textContent = '用户名长度必须在8到20个字符之间';
                return;
            }
            if (password.length < 8 || password.length > 20) {
                errorMessage.textContent = '密码长度必须在8到20个字符之间';
                return;
            }

            alert('登录成功！');
            // 这里可以添加代码将用户信息发送到服务器
        }
    </script>
</body>
</html>